package client.views.chatView;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import client.config.Public;
import client.models.ChatHistoryList;

import common.models.ChatHistoryItem;
import common.views.*;

public class ChatView extends MvcView implements ActionListener {
	
	private ChatFrame frame;
	private ChatHistoryList chatHistory;
	
/*	@Override
	public void update(Observable model, Object value) {
		if (model instanceof ChatHistoryList) {
			chatHistory = (ChatHistoryList) model;
		}
	}*/
	
	public ChatView(int friendID, String funame) {
		frame = new ChatFrame(friendID, Public.myProfile.getUserName(), funame);
		chatHistory = new ChatHistoryList(Public.myProfile.getUserID(), friendID);
		chatHistory.addView(this);
	}
	
	@Override
	public void update() {
		while (chatHistory.hasNextMessage()) {
			ChatHistoryItem item = chatHistory.getOneNewMessage();
			frame.say(item.getFrom() == Public.myProfile.getUserID(), item.getContent());
		}
	}
	
	public ChatFrame getFrame() { return frame; }
	public ChatHistoryList getModel() { return chatHistory; }

	public void actionPerformed(ActionEvent arg0) {
		// TODO Auto-generated method stub
		
	}
}
